﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using DWF.Studio.Custom;
using DWF.Studio.Host;
using DWF.Studio.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace DWF.Studio.Script
{
    /// <summary>
    /// 脚本基类
    /// </summary>
    internal abstract class ScriptBase : IDisposable
    {
        /// <summary>
        /// 工程路径
        /// </summary>
        public string ProjectDirectory
        {
            protected set;
            get;
        }

        /// <summary>
        /// 是否是启动项
        /// </summary>
        public bool IsStart
        {
            protected set;
            get;
        }

        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName
        {
            protected set;
            get;
        }

        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath
        {
            protected set;
            get;
        }

        /// <summary>
        /// 脚本编辑器
        /// </summary>
        public FrameworkElement ScriptEditor
        {
            protected set;
            get;
        }

        /// <summary>
        /// 编辑器内容改变
        /// </summary>
        public Action<EventArgs> EditorContentChanged
        {
            set;
            get;
        }

        public Action<BreakpointEventArgs> BreakPointChanged
        {
            set;
            get;
        }

        /// <summary>
        /// 编辑器是否更改过
        /// </summary>
        public bool IsEditorContentChanged
        {
            protected set;
            get;
        }

        /// <summary>
        /// 属性栏1
        /// </summary>
        public FrameworkElement PropertyBar1
        {
            protected set;
            get;
        }

        /// <summary>
        /// 属性栏2
        /// </summary>
        public FrameworkElement PropertyBar2
        {
            protected set;
            get;
        }

        public bool IsReadOnly
        {
            protected set;
            get;
        }

        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="newName"></param>
        public void Rename(string filePath, string newName)
        {
            this.FilePath = Path.Combine(Path.GetDirectoryName(filePath), newName);
            this.FileName = newName;
        }

        /// <summary>
        /// 加载
        /// </summary>
        public abstract void Load();

        /// <summary>
        /// 加载
        /// </summary>
        public abstract void Load(IEnumerable<Breakpoint> breakpoints);

        /// <summary>
        /// 保存
        /// </summary>
        public abstract void Save();

        /// <summary>
        /// 能否保持保存
        /// </summary>
        public abstract bool TrySave(out string messge);

        /// <summary>
        /// 设置断点
        /// </summary>
        public abstract void ToggleBreakPoint();
        /// <summary>
        /// 启用所有断点
        /// </summary>
        public abstract void EnableBreakPoint(IEnumerable<Breakpoint> breakpoints);
        /// <summary>
        /// 禁用所有断点
        /// </summary>
        public abstract void BoundedBreakPoint(IEnumerable<Breakpoint> breakpoints);
        /// <summary>
        /// 删除断点
        /// </summary>
        /// <param name="breakpoint"></param>
        public abstract void DeleteBreakPoint(Breakpoint breakpoint);
        /// <summary>
        /// 删除所有断点
        /// </summary>
        public abstract void DeleteAllBreakPoints(IEnumerable<Breakpoint> breakpoints);

        /// <summary>
        /// 释放
        /// </summary>
        public abstract void Dispose();

        public abstract void SetReadOnly(bool isReadOnly);

        public abstract void DebugStart();

        public abstract void DebugEnd();

        public abstract bool Debug(string location);

        public abstract bool DebugByStep(string location);

        public abstract bool Validate(out string message);

        public abstract void Cut();

        public abstract void Copy();

        public abstract void Paste();

        public abstract void Undo();

        public abstract void Redo();

        public abstract void Find();

        public abstract void Replace();
        public abstract void Notes();
        public abstract void CancelNotes();

        public abstract IEnumerable<Breakpoint> GetBreakpoints();

        public abstract void ClearCurrentLocation();
    }
}
